package com.example.apollo.component;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.alibaba.fastjson.JSON;

import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

/**
 * The type IntelliJ IDEA.
 * <p>
 *
 * @author liuxiaolu
 * @date 2021/12/17
 */
@Configuration
public class ApolloAutoUpdateConfig {

    private static final Logger logger = LoggerFactory.getLogger(ApolloAutoUpdateConfig.class);

    /**
     * "application" 为配置的dashboard url(Apollo的key为spring.cloud.sentinel.transport.dashboard)
     * 所在的namespace名称，需要根据实际情况修改
     **/
    @ApolloConfigChangeListener(value = {"application"})
    private void configChangeListener(ConfigChangeEvent changeEvent) {
        logger.info("收到Apollo配置更新:{}", JSON.toJSONString(changeEvent));

        for (String changedKey : changeEvent.changedKeys()) {
            ConfigChange configChange = changeEvent.getChange(changedKey);
            logger.info("configChange:{}", JSON.toJSONString(configChange));
        }

    }

}
